﻿
using Grpc.Core;
using GrpcProtos.UserService;
using Microsoft.Extensions.Options;
using SharedKernel.Infrastructure.Comm;
using SharedKernel.Infrastructure.Grpc.Options;
using UserService.Domain.Repositories;
using GrpcProtos.OrderService;
namespace UserService.Grpc.Services
{
    /// <summary>
    /// 用户微服务的Grpc实现
    /// </summary>
    public class UserGrpcServiceImpl : UserGrpcService.UserGrpcServiceBase
    {
        private readonly IUserRepository _userRepository;
        private readonly GrpcClientOptions _grpcClientOptions;
        private readonly OrderGrpcService.OrderGrpcServiceClient _orderClient;
        public UserGrpcServiceImpl(IUserRepository userRepository, IOptions<GrpcClientOptions> grpcClientOptions)
        {
            _userRepository = userRepository;
            _grpcClientOptions = grpcClientOptions.Value;
        }

        public override async Task<GetUserInfoResponse> GetUserInfo(GrpcProtos.UserService.EmptyRequest request, ServerCallContext context)
        {
            await Task.Delay(1);
            return new GetUserInfoResponse
            {
                Message = "操作成功",
                Code = 200,
            };
        }

        public override async Task<UserCreateOrderResponse> UserCreateOrder(UserCreateOrderRequest request, ServerCallContext context)
        {
            var res = await _orderClient.CreateOrderAsync(new GetBuyProductListRequest
            {
                UserId = 1
            });
            return await base.UserCreateOrder(request, context);
        }
    }
}
